package com.suray.system.run.data.mysql.analyze;

import com.suray.commin.core.utils.SpringContextHolder;
import com.suray.system.run.data.mysql.device.entity.ExecTaskDB;
import com.suray.system.run.data.mysql.device.entity.OffLineDesDB;
import com.suray.system.run.data.mysql.device.offline.OffLineDesDBServiceImpl;
import com.suray.system.run.type.DeviceType;

import java.util.Date;
import java.util.List;

public class OffLineDesDataStore {
    private OffLineDesDBServiceImpl offLineDesDBService = SpringContextHolder.getBean(OffLineDesDBServiceImpl.class);

    /**
     * 设备序列号
     */
    private String series;

    /**
     * 当前任务表
     */
    private OffLineDesDB offLineDesDB;

    /**
     * 设备类型
     */
    private DeviceType deviceType;

    public OffLineDesDataStore(String series, DeviceType deviceType) {
        this.series = series;
        this.deviceType = deviceType;
    }

    /**
     * 查找当前的离线信息
     * @return
     */
    public OffLineDesDB findOffLineDesData() {
        offLineDesDB = offLineDesDBService.findOffLineDesDBBySeries(series);
        return offLineDesDB;
    }

    /**
     * 创建当前小车离线信息
     * @return
     */
    public OffLineDesDB createOffLineDesData() {
        offLineDesDB = new OffLineDesDB();
        offLineDesDB.setSeries(series);
        offLineDesDB.setDeviceType(deviceType);
        offLineDesDBService.save(offLineDesDB);
        return offLineDesDB;
    }

    /**
     * 更新当前小车离线信息
     * @return
     */
    public boolean updateOffLineDesData() {
        return offLineDesDBService.updateById(offLineDesDB);
    }

    /**
     * 获取小车所有离线信息
     * @param startTime
     * @param endTime
     * @return
     */
    public List<OffLineDesDB> getOffLineList(Date startTime, Date endTime) {
        return offLineDesDBService.getOffLineList(series, startTime, endTime);
    }
}
